#include "init_server.h"
#include "clnt_connection.h"

int main(int argc, char **argv)
{
	int serv_sock;
	int clnt_sock;

	struct sockaddr_in serv_addr;
	struct sockaddr_in clnt_addr;

	int clnt_addr_size;

	char buf[BUFSIZ];
	pthread_t thread;

	if(argc != 2)
	{
		printf("Usage : %s <port>\n", argv[0]);
		exit(1);
	}

	init_server( serv_sock , serv_addr , argv);

	while(1)
	{
		clnt_addr_size = sizeof(clnt_addr);
		
		clnt_sock = accept(serv_sock, (struct sockaddr*)&clnt_addr, (socklen_t*)&clnt_addr_size);

		printf("연결 요청 : %s%d\n", inet_ntoa(clnt_addr.sin_addr), ntohs(clnt_addr.sin_port));

		pthread_create(&thread, NULL, clnt_connection, &clnt_sock);
	}

	return 0;
}

